package com.suncnpap.system.controller;



import com.app.util.common.ResponseUtil;
import com.github.pagehelper.PageInfo;
import com.suncnpap.system.model.Notice;
import com.suncnpap.system.model.NoticeVo;
import com.suncnpap.system.service.TNoticeNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.app.util.common.HandlerResult;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-11-27 21:45:28
 */
@RestController
@RequestMapping("/tnoticenotice")
public class TNoticeNoticeController{

    @Autowired
    private TNoticeNoticeService tNoticeNoticeService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list/{page}/{size}")
    public void list(@RequestBody(required = false) NoticeVo notice,
                     @PathVariable int page, @PathVariable int size,
                     HttpServletResponse response) throws Exception {

        HandlerResult result = new HandlerResult();//this.checkToken(request);
        long total=0L;
        int pageNum=0;
        List<Notice> list=null;
        int pageSize=0;
        if (result.getCode()==0) {
            PageInfo<Notice> NoticeList = tNoticeNoticeService.getNoticestrSchoolIdList(notice,page,size);
            pageNum = NoticeList.getPageNum();
            pageSize = NoticeList.getPageSize();
            list = NoticeList.getList();
            total = NoticeList.getTotal();
        }
        result.put("list",list);
        result.put("total",total);
        result.put("pageNum",pageNum);
        result.put("pageSize",pageSize);
        ResponseUtil.writeJson(result, response);
    }

    @RequestMapping(value = "/details/{id}")
    public void getDetails(HttpServletResponse response,@PathVariable String id)throws Exception{
        HandlerResult result = new HandlerResult();
        Notice notice=null;
        if(result.getCode()==0){
           notice=tNoticeNoticeService.details(id);

        }
        result.put("notice",notice);
        ResponseUtil.writeJson(result, response);
    }
    @RequestMapping(value = "/hits/{id}")
    public void getHits(HttpServletResponse response,@PathVariable String id)throws Exception {
        HandlerResult result = new HandlerResult();
        Integer notice=0;
        if(result.getCode()==0){
            notice=tNoticeNoticeService.hits(id);
        }
        result.put("notice",notice);
        ResponseUtil.writeJson(result, response);
    }



}

